<?php
namespace MobileHome\Controller;

class AboutController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function indexAction()
    {
        $returnData = array();
        $cat_id = I('get.id', 0, 'intval');
        $condition = array(
            'type' => 1,
            'parent_id' => $cat_id,
        );
        $list = M('SinglePageCategory')->where($condition)->select();
        if (1 == count($list)) {
            $cat_id = $list[0]['id'];
        }
        if (1 == count($list) || empty($list)) {
            $this->detailAction($cat_id);
            exit;
//            redirect(U('About/detail', array('cat_id' => $cat_id)));
        }
        foreach ($list as $item) {
            $returnData[] = array(
                'imgurl' => $item['pic'],
                'tit' => $item['name'],
                'word' => '',
            );
        }
        $returnData = json_encode($returnData);
        $this->assign('jsonData', $returnData);
        $this->assign('list', $list);
        $this->display('index');
    }

    public function detailAction($cat_id)
    {
        $cat_id = isset($cat_id) ? $cat_id : I('GET.cat_id', 0, 'intval');
        $page_info = array();
        $condition = array(
            'cat_id' => $cat_id,
        );
        $page_list = M('SinglePage')->where($condition)->order('id desc')->limit(1)->select();
        if ($page_list) {
            $page_info = $page_list[0];
        }
        $global_config = array(
            'title' => $page_info['title'] . '-' . C('SITE_NAME'),
            'keywords' => $page_info['title'],
            'description' => $page_info['title'],
        );
        $this->assign('global_config', $global_config);
        $this->assign('cat_id', $cat_id);
        $this->assign('page_info', $page_info);
        $this->display('detail');
    }

    /*
     * 全景看房
     */
    public function roomAction()
    {
        $type = I('GET.type', 'a', 'trim');
        $global_config = array(
            'title' => '全景看房' . '-' . C('SITE_NAME'),
            'keywords' => '全景看房',
            'description' => '全景看房',
        );
        $this->assign('global_config', $global_config);
        $tpl = 'room' . strtoupper($type);
        $this->display($tpl);
    }

    public function roomMapAction()
    {
        $id = I('get.id', 0, 'intval');
        $map = [
            '0' => [
                'title' => '大堂',
                'code' => 'http://720yun.com/t/01ajOgykuk1',
            ],
            '1' => [
                'title' => '区内<br/>私家花园',
                'code' => 'http://720yun.com/t/a97jOgyfsv1',
            ],
            '2' => [
                'title' => '区内<br/>私家花园<br/>(夜景)',
                'code' => 'http://720yun.com/t/8dejOgyfsf7',
            ],
            '3' => [
                'title' => '卧室',
                'code' => 'http://720yun.com/t/f9ajOgykrn9',
            ],
            '4' => [
                'title' => '卫生间',
                'code' => 'http://720yun.com/t/b18jOgykuO9',
            ],
        ];
        $global_config = array(
            'title' => '全景看房',
            'keywords' => '全景看房',
            'description' => '全景看房',
        );
        $this->assign('global_config', $global_config);
        $this->assign('map_info', $map[$id]);
        $this->assign('map', $map);
        $this->display();
    }

    public function linkUsAction()
    {
        $global_config = array(
            'title' => '联系我们',
            'keywords' => '联系我们',
            'description' => '联系我们',
        );
        $this->assign('global_config', $global_config);
        $this->display();
    }

    public function mapAction()
    {
        $this->display();
    }
}